

package cn.shengchao;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import cn.shengchao.cap.domain.order.CapOrderCreateDto;
import cn.shengchao.cap.domain.order.CapOrderUtils;
import cn.shengchao.cap.domain.token.CapProperties;
import cn.shengchao.cap.domain.token.CapTokenUtil;
import cn.shengchao.examstar.me.collect.acl.ports.repositories.IUserCollectInfoRepository;
import cn.shengchao.examstart.user.acl.adapters.repositories.UserRepository;
import cn.shengchao.examstart.user.domain.entity.User;
import cn.shengchao.ycbdc.domain.result.UserInfoResult;
import cn.shengchao.ycbdc.domain.token.YcBdcTokenUtil;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.ActiveProfiles;

import java.util.Date;

/**
 * @program: examstarapi
 * @description: sda
 * @author: Xiong weiqiang
 * @create: 2025-03-31 13:57
 */

@SpringBootTest(classes = cn.shengchao.ExamstartRunApplication.class)
@ActiveProfiles("xwq")
public class ApplicationTest1 {
    @Autowired
    private IUserCollectInfoRepository userCollectInfoRepository;
    @Autowired
    RedisTemplate<String, Object> redisTemplate;
    @Autowired
    CapProperties capProperties;
    @Autowired
    CapTokenUtil capTokenUtil;
    @Autowired
    CapOrderUtils capOrderUtils;
    @Autowired
    private UserRepository userRepository;

    @Autowired
    private YcBdcTokenUtil ycBdcTokenUtil;
    @Test
    public void testYcBdcTest() {
        boolean buyDaySuccess=ycBdcTokenUtil.addOrderDays("13233333333","xwq1233",30);
        Assert.assertTrue(buyDaySuccess);
        UserInfoResult userInfoResult=ycBdcTokenUtil.getUserInfo("13233333333","xwq1233");
        Date expirationDate=userInfoResult.getExpirationDate();
        Assert.assertNotNull(expirationDate);
        Assert.assertTrue(expirationDate.after(new Date()));
    }
    @Test
    public void testUserCollectInfo() {
       User user= userRepository.of(713397186175451510L);
       System.out.println("user="+ JSONUtil.toJsonStr(user));
       //用户手机明码
    }
    /**
     *
     * 注意对方的orderCode和自己的不一样
     * Response body: {
     *   "success": true,
     *   "code": 200,
     *   "count": 0,
     *   "data": {
     *     "orderCode": "2025052210254090150086"
     *   },
     *   "msg": ""
     * }
     */
    @Test
    public void testThirdCAP(){
        Assert.assertNotNull(capProperties);
        String token=capTokenUtil.getToken();
        System.out.println("TOKEN="+token);
        Assert.assertNotNull(token);

        String b=capOrderUtils.createOrder(CapOrderCreateDto.builder()
                .orderCode("20250331000000000003")
                //第三方验证了手机号？
                //.userName("xwq1233")
                .userName("13233333333")
                .graduationYear(2025)
                .build());
        //重复：订单号已存在！用户如果重复购买不会管
        Assert.assertTrue(StrUtil.isNotBlank(b));
    }
//    @Test
//    public void testRedisTemplatesExist(){
//        Assert.assertNotNull(redisTemplate);
//        redisTemplate.opsForValue().set("test", "test1");
//        String test1 = (String)redisTemplate.opsForValue().getAndDelete("test");
//        Assert.assertTrue(Objects.equals(test1, "test1"));
//        Assert.assertNull(redisTemplate.opsForValue().get("test"));
//    }
//    @Test
//    public void testSecurityEnDecrpt() {
//        System.out.println("13234567891 aces encode=" + SecureUtils.encryptFieldByAes("13234567891"));
//        System.out.println("13300000091 aces encode=" + SecureUtils.encryptFieldByAes("13300000091"));
//        System.out.println("13300000092 aces encode=" + SecureUtils.encryptFieldByAes("13300000092"));
//        System.out.println("13300000093 aces encode=" + SecureUtils.encryptFieldByAes("13300000093"));
//        System.out.println("13300000103 aces encode=" + SecureUtils.encryptFieldByAes("13300000103"));
//        System.out.println("13300000104 aces encode=" + SecureUtils.encryptFieldByAes("13300000104"));
//        System.out.println("13600000002 aces encode=" + SecureUtils.encryptFieldByAes("13600000002"));
//        System.out.println("13300000105 aces encode=" + SecureUtils.encryptFieldByAes("13300000105"));
//        System.out.println("13300000106 aces encode=" + SecureUtils.encryptFieldByAes("13300000106"));
//    }

//    @Test
//    public void testUserCollectInfoJsonField() {
//        UserCollectInfo userCollectInfo=userCollectInfoRepository.getUserCollectInfo(10232121312321L);
//        Assert.assertNull(userCollectInfo);
//        UserCollectInfo userCollectInfo1=userCollectInfoRepository.getUserCollectInfo(1L);
//        System.out.println(JSONUtil.toJsonStr(userCollectInfo1));
//        Set<String> tags=userCollectInfo1.getTags();
//        //null更新无效
//
//        userCollectInfo1.setTags(Set.of("老六","老七"));
//        userCollectInfoRepository.saveUserCollectInfo(userCollectInfo1);
//        userCollectInfo1=userCollectInfoRepository.getUserCollectInfo(1L);
//        Assert.assertNull(userCollectInfo1.getTags());
//    }
}